package utils


private val hex: CharArray = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')

fun byte2hex(b: ByteArray, isLowerCase: Boolean): String {
    val sb = StringBuilder()
    for (i in b.indices) {
        val v = b[i].toInt() and 0xFF
        val h = v / 16
        val l = v % 16
        sb.append(hex[h].let { if (isLowerCase) it else it.uppercaseChar() })
        sb.append(hex[l].let { if (isLowerCase) it else it.uppercaseChar() })
    }
    return sb.toString()
}